/**
 * 
 * @param {*} elem 滚动的元素
 * @param {*} options 滚动配置
 */
export function scrollIntoView(elem, options) {
  options = {
    duration: 1000,
    ease: 'ease-out',
    ...options,
  }

  var scrollOffset = elem.getBoundingClientRect().top - options.offset,
    totalScrollOffset = window.scrollY + scrollOffset,
    duration = options.duration,
    startTime = Date.now(),
    distance,
    currentScrollPosition;

  requestAnimationFrame(function anim() {
    currentScrollPosition = window.scrollY;
    distance = totalScrollOffset - currentScrollPosition;

    var elapsed = Date.now() - startTime;
    var progress = Math.min(1, elapsed / duration);

    window.scrollTo(0, currentScrollPosition + (distance * progress));

    if (progress < 1 && distance !== 0) {
      requestAnimationFrame(anim);
    }
  });
}